package com.atguigu.daijia.customer.controller;

import com.atguigu.daijia.common.login.GuiguLogin;
import com.atguigu.daijia.common.result.Result;
import com.atguigu.daijia.common.util.AuthContextHolder;
import com.atguigu.daijia.customer.service.CouponService;
import com.atguigu.daijia.model.vo.base.PageVo;
import com.atguigu.daijia.model.vo.coupon.AvailableCouponVo;
import com.atguigu.daijia.model.vo.coupon.NoReceiveCouponVo;
import com.atguigu.daijia.model.vo.coupon.NoUseCouponVo;
import com.atguigu.daijia.model.vo.coupon.UsedCouponVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Tag(name = "优惠券活动接口管理")
@RestController
@RequestMapping(value="/coupon")
@SuppressWarnings({"unchecked", "rawtypes"})
@RequiredArgsConstructor
public class CouponController {

    private final CouponService couponService;

    /**
     * 分页查询乘客未领取的优惠券列表
     * @param page
     * @param limit
     * @return
     */
    @Operation(summary = "分页查询乘客未领取的优惠券列表")
    @GuiguLogin
    @GetMapping("/findNoReceivePage/{page}/{limit}")
    public Result<PageVo<NoReceiveCouponVo>> findNoReceiveCouponPage(@PathVariable("page") Long page, @PathVariable("limit") Long limit) {
        Long customerId = AuthContextHolder.getUserId();
        PageVo<NoReceiveCouponVo> pageVo = couponService.findNoReceiveCouponPage(customerId, page, limit);
        return Result.ok(pageVo);
    }

    /**
     * 分页查询乘客未使用的优惠券列表
     * @param page
     * @param limit
     * @return
     */
    @Operation(summary = "分页查询乘客未使用的优惠券列表")
    @GuiguLogin
    @GetMapping("/findNoUsePage/{page}/{limit}")
    public Result<PageVo<NoUseCouponVo>> findNoUseCouponPage(@PathVariable("page") Long page, @PathVariable("limit") Long limit) {
        Long customerId = AuthContextHolder.getUserId();
        PageVo<NoUseCouponVo> pageVo = couponService.findNoUseCouponPage(customerId, page, limit);
        return Result.ok(pageVo);
    }

    /**
     * 分页查询乘客已使用的优惠券列表
     * @param page
     * @param limit
     * @return
     */
    @Operation(summary = "分页查询乘客已使用的优惠券列表")
    @GuiguLogin
    @GetMapping("/findUsedPage/{page}/{limit}")
    public Result<PageVo<UsedCouponVo>> findUsedCouponPage(@PathVariable("page") Long page, @PathVariable("limit") Long limit) {
        Long customerId = AuthContextHolder.getUserId();
        PageVo<UsedCouponVo> pageVo = couponService.findUsedCouponPage(customerId, page, limit);
        return Result.ok(pageVo);
    }

    /**
     * 领取优惠券
     * @param couponId
     * @return
     */
    @Operation(summary = "领取优惠券")
    @GuiguLogin
    @GetMapping("/receive/{couponId}")
    public Result<Boolean> receiveCoupon(@PathVariable("couponId") Long couponId) {
        Long customerId = AuthContextHolder.getUserId();
        Boolean result = couponService.receiveCoupon(customerId, couponId);
        return Result.ok(result);
    }

    /**
     * 查询可用优惠券列表
     * @param orderId
     * @return
     */
    @Operation(summary = "查询可用优惠券列表")
    @GuiguLogin
    @GetMapping("/findAvailableCoupon/{orderId}")
    public Result<List<AvailableCouponVo>> findAvailableCouponList(@PathVariable("orderId") Long orderId) {
        Long customerId = AuthContextHolder.getUserId();
        List<AvailableCouponVo> list = couponService.findAvailableCouponList(customerId, orderId);
        return Result.ok(list);
    }

}

